import Vue from 'vue'
import VueRouter from 'vue-router'
import * as token from '@/utils/auth.js'

Vue.use(VueRouter)


// 公共
const Login = () => import('../views/Login.vue');
const Home = () => import('../views/Home.vue');
const Profile = () => import('../views/Profile.vue');

// 场所管理系统 
const CSMHome = () => import('../views/csm/CSMHome.vue');
const CSMDashboard = () => import('../views/csm/Dashboard.vue')
const CSMCSMManage = () => import('../views/csm/csmManage/CSMManage.vue')
const CSMCSMReport = () => import('../views/csm/csmManage/CSMReport.vue')
const CSMCSMManageDetail = () => import('../views/csm/csmManage/CSMManageDetail.vue')
const CSMOrgService = () => import('../views/csm/orgService/OrgService.vue')
const CSMOrgServiceDetail = () => import('../views/csm/orgService/OrgServiceDetail.vue')
const CSMCodeMoni = () => import('../views/csm/codeMoni/CodeMoni.vue')
const CSMCodeMoniDetail = () => import('../views/csm/codeMoni/CodeMoniDetail.vue')
const CSMCodeWarning = () => import('../views/csm/codeWarning/CodeWarning.vue')
const CSMCodeWarningDetail = () => import('../views/csm/codeWarning/CodeWarningDetail.vue')
const CSMAreaReport = () => import('../views/csm/areaReport/AreaReport.vue')
const CSMPlaceReport = () => import('../views/csm/placeReport/PlaceReport.vue')
const CSMVehicleReport = () => import('../views/csm/vehicleReport/VehicleReport.vue')
const CSMVehicleReportList = () => import('../views/csm/vehicleReport/VehicleReportList.vue')
const CSMVehicleReportDetail = () => import('../views/csm/vehicleReport/VehicleReportDetail.vue')
const CSMCSMManager = () => import('../views/csm/csmManager/CSMManager.vue')
const CSMCSMManagerDetail = () => import('../views/csm/csmManager/CSMManagerDetail.vue')
const CSMCSMHistory = () => import('../views/csm/csmHistory/CSMHistory.vue')


// 防控管理系统
const FKHome = () => import('../views/fk/FKHome.vue');
const FKDashboard = () => import('../views/fk/Dashboard.vue');
const FKCSMLog = () => import('../views/fk/csmLog/CSMLog.vue');
const FKTerminalLog = () => import('../views/fk/terminalLog/TerminalLog.vue');
const FKCodeForewarning = () => import('../views/fk/codeForewarning/CodeForewarning.vue');
const FKCodeForewarningDetail = () => import('../views/fk/codeForewarning/CodeForewarningDetail.vue');
const FKPlaceForewarning = () => import('../views/fk/placeForewarning/PlaceForewarning.vue');
const FKPlaceForewarningDetail = () => import('../views/fk/placeForewarning/PlaceForewarningDetail.vue');
const FKCSMAreaReport = () => import('../views/fk/csm-areaReport/AreaReport.vue');
const FKCSMPlaceReport = () => import('../views/fk/csm-placeReport/PlaceReport.vue');
const FKEQAreaReport = () => import('../views/fk/eq-areaReport/AreaReport.vue');
const FKEQEquipReport = () => import('../views/fk/eq-equipReport/EquipReport.vue');
const FKHealthAreaReport = () => import('../views/fk/healthAreaReport/HealthAreaReport.vue');
const FKHsAreaReport = () => import('../views/fk/hsAreaReport/HsAreaReport.vue');
const FKHealthCodeAreaReport = () => import('../views/fk/healthCodeAreaReport/HealthCodeAreaReport.vue');
const FKViaGzReport = () => import('../views/fk/viaGz/ViaGzReport.vue');
const FKViaGzDetail = () => import('../views/fk/viaGz/ViaGzDetail.vue');


// 平台管理系统
const PLAPlatformHome = () => import('../views/platform/PlatformHome.vue');
const PLADashboard = () => import('../views/platform/Dashboard.vue');
const PLAMenu = () => import('../views/platform/menu/Menu.vue');
const PLARole = () => import('../views/platform/role/Role.vue');
const PLAUser = () => import('../views/platform/user/User.vue');

const PREFIX_PATH = '/eve';
const TestHome = () => import('../views/TestHome.vue');
const routes = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/test',
    component: TestHome
  },
  {
    path: '/home',
    component: Home
  },
  {
    path: '/csm',
    name: 'CSMHome',
    meta: {
      title: '场所码管理'
    },
    component: CSMHome,
    redirect: '/csm/dashboard',
    children: [{
      path: 'dashboard',
      meta: {
        title: '首页'
      },
      component: CSMDashboard
    },{
      path: 'profile',
      component: Profile,
      meta: {
        title: '个人中心'
      },
    },{
      path: 'csmManage',
      component: CSMCSMManage,
      meta: {
        title: '场所码管理列表'
      },
    },{
      path: 'csmManager',
      component: CSMCSMManager,
      meta: {
        title: '场所码管理人员'
      },
    },{
      path: 'csmManagerDetail',
      component: CSMCSMManagerDetail,
      meta: {
        title: '场所码管理人员详情'
      },
    },{
      path: 'csmReport',
      component: CSMCSMReport,
      meta: {
        title: '场所码查询列表'
      },
    },{
      path: 'csmManageDetail',
      component: CSMCSMManageDetail,
      meta: {
        title: '场所码详情'
      },
    },{
      path: 'orgService',
      meta: {
        title: '组织机构列表'
      },
      component: CSMOrgService
    },{
      path: 'orgServiceDetail',
      meta: {
        title: '组织机构详情'
      },
      component: CSMOrgServiceDetail
    },{
      path: 'codeMoni',
      meta: {
        title: '码监控列表'
      },
      component: CSMCodeMoni
    },{
      path: 'codeMoniDetail',
      meta: {
        title: '码监控详情'
      },
      component: CSMCodeMoniDetail
    },{
      path: 'codeWarning',
      meta: {
        title: '码预警列表'
      },
      component: CSMCodeWarning
    },{
      path: 'codeWarningDetail',
      meta: {
        title: '码预警详情'
      },
      component: CSMCodeWarningDetail
    },{
      path: 'areaReport',
      meta: {
        title: '区域报表'
      },
      component: CSMAreaReport
    },{
      path: 'placeReport',
      meta: {
        title: '场所报表'
      },
      component: CSMPlaceReport
    },{
      path: 'csmHistory',
      meta: {
        title: '场所码修改日志'
      },
      component: CSMCSMHistory
    }]
  },
  {
    path: '/fk',
    name: 'FKHome',
    meta: {
      title: '防控管理'
    },
    component: FKHome,
    redirect: '/fk/dashboard',
    children: [{
      path: 'dashboard',
      meta: {
        title: '首页'
      },
      component: FKDashboard
    },{
      path: 'profile',
      meta: {
        title: '个人中心'
      },
      component: Profile
    },{
      path: 'csmLog',
      meta: {
        title: '场所码日志'
      },
      component: FKCSMLog
    },{
      path: 'terminalLog',
      meta: {
        title: '终端扫码日志'
      },
      component: FKTerminalLog
    },{
      path: 'codeForewarning',
      meta: {
        title: '扫码预警'
      },
      component: FKCodeForewarning
    },{
      path: 'codeForewarningDetail',
      meta: {
        title: '扫码预警详情'
      },
      component: FKCodeForewarningDetail
    },{
      path: 'placeForewarning',
      meta: {
        title: '场所预警'
      },
      component: FKPlaceForewarning
    },{
      path: 'placeForewarningDetail',
      meta: {
        title: '场所预警详情'
      },
      component: FKPlaceForewarningDetail
    },{
      path: 'csm-areaReport',
      meta: {
        title: '场所码-区域统计'
      },
      component: FKCSMAreaReport
    },{
      path: 'csm-placeReport',
      meta: {
        title: '场所码-场所统计'
      },
      component: FKCSMPlaceReport
    },{
      path: 'eq-areaReport',
      meta: {
        title: '设备码-区域统计'
      },
      component: FKEQAreaReport
    },{
      path: 'eq-equipReport',
      meta: {
        title: '设备码-设备统计'
      },
      component: FKEQEquipReport
    },{
      path: 'vehicleReport',
      meta: {
        title: '站点排查统计'
      },
      component: CSMVehicleReport
    },{
      path: 'vehicleReportList',
      meta: {
        title: '站点排查统计'
      },
      component: CSMVehicleReportList
    },{
      path: 'vehicleReportDetail',
      meta: {
        title: '站点车辆明细'
      },
      component: CSMVehicleReportDetail
    },{
      path: 'healthReport',
      meta: {
        title: '健康申报区域统计'
      },
      component: FKHealthAreaReport
    },{
      path: 'hsAreaReport',
      meta: {
        title: '核酸检测区域统计'
      },
      component: FKHsAreaReport
    },{
      path: 'healthCodeAreaReport',
      meta: {
        title: '健康码区域统计'
      },
      component: FKHealthCodeAreaReport
    },{
      path: 'viaGzReport',
      meta: {
        title: '旅居省返黔统计'
      },
      component: FKViaGzReport
    },{
      path: 'viaGzDetail',
      meta: {
        title: '旅居省返黔明细'
      },
      component: FKViaGzDetail
    }]
  },
  {
    path: '/pla',
    name: 'PLAPlatformHome',
    meta: {
      title: '平台管理'
    },
    component: PLAPlatformHome,
    redirect: '/pla/dashboard',
    children: [{
      path: 'dashboard',
      meta: {
        title: '首页'
      },
      component: PLADashboard
    },{
      path: 'profile',
      meta: {
        title: '个人中心'
      },
      component: Profile
    },{
      path: 'menu',
      meta: {
        title: '菜单管理'
      },
      component: PLAMenu
    },{
      path: 'role',
      meta: {
        title: '角色管理'
      },
      component: PLARole
    },{
      path: 'user',
      meta: {
        title: '用户管理'
      },
      component: PLAUser
    }]
  }
]


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


// 白名单
const whiteList = ['/login']

// 定义路由导航
router.beforeEach((to, from, next) => {
  // 此处获取token
  const k = token.get();
  if(k){
    // has token
    if(to.path === '/login'){
      // 为登录页
      next({ path: '/home'})
    } else{
      // 判断当前用户是否已拉取完user_info信息
      // if(store.getters.roles.length == 0){
        // 未拉取
      // }else {
        // 已拉取
      //   next()
      // }
      next()
    }
  }else{
    // no token
    if(to.path != '/' && whiteList.indexOf(to.path) > -1){
      next()
    } else{
      next('/login')
    }
  }
})

export default router
